package org.lboot.flow;

import org.lboot.flow.constant.FlowWorkStatusEnum;
import org.lboot.flow.module.assign.FlowTaskAssign;
import org.lboot.flow.module.define.FlowDefine;
import org.lboot.flow.module.event.FlowCustomEvent;
import org.lboot.flow.module.event.FlowEvent;
import org.lboot.flow.module.work.FlowWork;
import org.lboot.flow.module.work.params.FlowDecisionTaskParams;
import org.lboot.flow.module.work.params.FlowStartParams;
import org.lboot.flow.module.work.params.FlowTaskParams;

import java.util.List;

/**
 * @author kindear
 * 流程调度控制器
 */
public interface FlowCtl {
    /**
     * 流程启动
     * @param params
     * @return FlowWork
     */
    FlowWork startFlow(FlowStartParams params);

    /**
     * 流程取消
     * @param flowWorkId
     * @return
     */
    FlowWork cancelFlow(String flowWorkId);

    /**
     * 流程删除
     * @param flowWorkId
     * @return
     */
    FlowWork deleteFlow(String flowWorkId);

    /**
     * 流程回退
     * @param flowWorkId 流程实例ID
     * @param backNodeId 回退节点ID
     * @return
     */
    FlowWork backFlow(String flowWorkId, String backNodeId);

    /**
     * 新增流程审核指派
     * @param flowDefineCode
     * @param flowNodeId
     * @param assignType
     * @param assignId
     * @return
     */
    FlowTaskAssign createAssign(String flowDefineCode, String flowNodeId, String assignType, String assignId);


    /**
     * 删除流程审核指派
     * @param id
     * @return
     */
    FlowTaskAssign deleteAssign(String id);

    /**
     * 流程启动
     * @return FlowWork
     */
    default FlowWork startProcess(FlowStartParams params){
        return startFlow(params);
    }


    /**
     * 确定决策
     * @param params
     * @return
     */
    boolean decisionTask(FlowDecisionTaskParams params);

    /**
     * 审核通过
     * @return
     */
    boolean completeTask(FlowTaskParams params);

    /**
     * 审核通过
     * @param params
     * @return
     */
    default boolean passTask(FlowTaskParams params){
        return completeTask(params);
    }

    /**
     * 审核拒绝
     * @param params
     * @return
     */
    boolean rejectTask(FlowTaskParams params);

    /**
     * 审核拒绝
     * @param params
     * @return
     */
    default boolean refuseTask(FlowTaskParams params){
        return rejectTask(params);
    }

    /**
     * 修改流程状态
     * @param flowWorkId
     * @param statusEnum
     * @return
     */
    FlowWork modifyFlowStatus(String flowWorkId, FlowWorkStatusEnum statusEnum);

    FlowWork modifyFlowStatus(FlowWork flowWork, FlowWorkStatusEnum statusEnum);

    /**
     * 触发事件
     * @param flowWork
     * @param event
     */
    void invokeEvent(FlowWork flowWork, FlowEvent event);


}
